/**
 * Created by limeng on 16/9/1.
 */
indexApp.controller("ProposalDetailCtrl", function ($scope, $http, $routeParams) {
    $scope.secondMotionList = [];
    $scope.secondMotionPageNo = 1;
    $scope.showMoreMotion = false;
    $scope.attachments = [];
    $scope.proposal = {};

    $scope.proposalId = $routeParams.proposalId;

    $http.get("/proposal/"+$scope.proposalId).success(function (data) {
        if (data.state == true) {
            $scope.proposal = data.proposal;
            var contentElem = document.getElementById("proposalContent");
            contentElem.innerHTML = $scope.proposal.content;
            contentElem.style.padding = 15;
        }
    });
    $http.get("/attachment/proposalId/"+$scope.proposalId).success(function (data) {
        if (data) {
            $scope.attachments = data;
        }
    });


    $scope.refreshMotionList = function() {
        $http.get('/second_motion/' + $scope.proposalId
            + '/10/' + ($scope.secondMotionPageNo++)
        ).success(
            function (data) {
                if (data.state == true) {
                    for (var i = 0; i < data.list.length; i++) {
                        $scope.secondMotionList.push(data.list[i]);
                    }
                    if ($scope.secondMotionPageNo <= data.pageCount) {
                        $scope.showMoreMotion = true;
                    } else {
                        $scope.showMoreMotion = false;
                    }
                } else {
                    alert('查询失败,原因:'+data.result);
                }
            }
        ).error(
            function () {
                alert('查询失败,附议信息数据库出现异常');
            }
        );
    };
    $scope.refreshMotionList();

    $(".nav_elem").removeClass("jc_li_selected");
});